LoginController = BaseController.extend({
	template: 'Login',
	mainView: 'login-view login-screen',
	mobile: '',
	password: '',
	newUser: true,
	waitOn: function () {
		
	},
	appInit: function () {

	},
	login: function () {

	},
	onRendered: function (controller) {
		controller.app.loginScreen()
	},
	beforeAction: function () {
		if (localStorage.token) {
			this.router.go('home');
			return null;
		}
		return this.next();
	},
	events: function (controller) {
		return {
			'click #login-button': function (e) {
				let name = $('#user_name').val();
				let password = CryptoJS.MD5($('#password').val()).toString();
				if(name && password){
					controller.post('auth/sign-up', {user_name:name, password:password}).then(function (res) {
						if (res.data.state == "OK") { 
							LoginToken.insert(res.data.data.token);
							localStorage.token = res.data.data.token.token;
							controller.router.go('home');
						} else {
							controller.app.alert(res.data.message);
						}
					}, function (error) {
						console.log(error);
					});
				}else{
					controller.app.alert('请填写用户名或密码');
				}
			},
			'click .remember-me .check-box': function (e) {
				if ($(e.currentTarget).attr('checked') == "checked") {
					$(e.currentTarget).find('i').removeClass('hidden');
					$(e.currentTarget).removeAttr('checked');
				} else {
					$(e.currentTarget).find('i').addClass('hidden');
					$(e.currentTarget).attr('checked', 'checked');
				}
			}
		};
	},
	data: function () {
		return {};
	}
});
